home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-06-03 | 54.7 KB | 1,357 lines |
- MOUSE V3.1
- as of 28 May 1989
- Author: Michael Day
-
- This program is released to the public domain by the author.
-
-
-
-
- Mouse has gone through a number of major rewrites since it
- was originally introduced. This latest release has changed the way
- some of the functions work. If you are using the old mouse
- program, you will most likely have to make some minor changes to
- your program to use this new version of Mouse.
-
- The most significant difference is how the mouse positioning
- is being handled now. In the earlier Mouse program there were
- separate routines for the text and graphics mouse positioning,
- and separate variables. This is no longer the case. The double
- routines have been merged into single routines with a flag to
- (TextMouse) control whether the position data is treated as text
- positioning or graphics positioning. Further, new functions have
- been added to convert the virtual position information provided
- by the mouse back to real screen positioning needed by programs.
-
- To properly set the mouse position, or read the position of
- the mouse, you should now use the translation functions to
- correctly derive the proper mouse position on the screen. The
- advantage to this is that the translation routines are
- intelligent enough to be able to properly convert the positioning
- information based on the current display type and mode. The
- standard CGA, EGA, VGA, and Hercules displays and their modes are
- supported. Note: most mouse drivers do not support extended or
- non-standard display modes. You may need to override the mouse
- position translator with your own if you use a non-standard mode.
-
- The other big change is the addition of the simulated mouse
- cursor. Why a simulated mouse cursor? Two reasons, one, if you
- don't have a mouse, you can still make believe that you do by
- using the simulated cursor and keyboard input. And two, it gets
- around a problem with Turbo Pascal in that it is not well behaved
- when it comes to mice. Turbo Pascal and the Turbo Debugger will
- trash the mouse cursor when using the standard mouse driver to
- generate the cursor. You can get around this by using the
- simulated cursor instead. Since it operates via the program,
- Turbo Pascal and Turbo Debugger are happy. There is one
- disadvantage though, if the simulated mouse is used the cursor
- operation will be slow and jerky. I recommend that you continue
- to use the driver generated mouse cursor for commercial
- applications where possible. The simulated mouse is mainly to
- allow you to use a mouse while debugging a program or to run a
- program without a mouse at all.
-
-
-
- ISR Support:
-
- Another addition is ISR support for the mouse so that you
- don't have to sprinkle ReadMouse calls through out your program.
- This can make mouse programming much simpler.
-
-
-
- Graphic Mouse Cursor:
-
- There are 19 supplied Graphic mouse cursors in the program.
- You can select the desired cursor by calling the
- MouseGraphicCursor function which will cause the selected cursor
- to be loaded from the table. You can see which cursor has been
- loaded by looking at the global MouseGStyle variable. If
- MouseGStyle contains a -1 it means that a custom cursor has been
- loaded. You can load your own custom graphic mouse cursor by
- using the SetMouseGraphicCursor function.
-
-
-
- Text Mouse Cursor:
-
- There are 16 supplied Text mouse cursors in the program. You
- can select the desired cursor by calling the MouseTextCursor
- function which will cause the selected cursor to be loaded from
- the table. You can see which cursor has been loaded by looking at
- the global MouseTStyle variable. If MouseTStyle contains a -1 it
- means that a custom cursor has been loaded. If MouseTStyle
- contains a 0, then the current hardware cursor is used. You can
- load your own custom text mouse cursor by using the
- SetMouseTextCursor function.
-
- The TextMouse flag is used to identified whether the mouse
- is currently in text or graphics mode. Calling the MouseInit
- procedure will cause the TextMouse flag to be set based on the
- value found in the BIOS CrtMode flag.
-
- if you are using a non-standard or extended display mode
- (graphic or text), the mouse position translation routines may
- not be able to correctly translate the screen position to the
- virtual mouse position used by the mouse driver. You can however
- override the mouse position control variables after calling
- InitMouse to perform your own translation.
-
-
-
- Mouse Installation:
-
- The Mouse program expects a MicroSoft or compatible mouse
- driver to be installed on the computer. All mouse operations are
- performed through the mouse interrupt ($33). For more information
- on using the mouse interrupt refer to the MicroSoft Mouse
- Programmer's Reference Guide available from MicroSoft or though
- various computer book stores.
-
- If the mouse driver has not been installed, then the
- InitMouse procedure will set the MouseInstalled flag to false and
- most mouse procedures will immediately terminate if called. The
- basic mouse functions will continue to operate however if your
- program updates the MouseX and MouseY mouse positioning
- variables. This allows keyboard mouse emulation if the mouse is
- not available.
-
-
-
- Starting out:
-
- The first thing to do to get the mouse going is to call the
- InitMouse function near the beginning of your program before you
- use the other mouse functions.
-
- The InitMouse function initailizes the mouse driver to a
- predefined state. You can call the InitMouse function at anytime,
- but you should realize that any previous state will be lost.
-
- Special note about Hercules:
-
- If you are using a Hercules display, then you must
- call the SetHercMouse function before calling the InitMouse
- function. This is because the mouse driver must know which
- display page and mode of the Hercules card you are using.
- Also be sure to call the SetHercMouse function with a -1 to
- return it to text mode when you switch back to text mode.
- An exit procedure has been provided in Mouse which will
- properly restore the function when you exit your program.
-
- The reason for this special handling is that the
- hercules card does not provide any way for the system to
- know if it is in text mode or graphics mode, and if in
- graphics mode which page is selected. As such, this
- information must be maintain by the user program. The
- MicroSoft mouse driver uses the CrtMode variable to find
- this information and leaves it up to the user program to
- properly set the variable for desired operation.
-
-
-
-
- Showing the Mouse:
-
- Once you have the mouse initialized, You can make it appear
- on the screen by calling the ShowMouse function.
-
- If the mouse was previously hidden, you must call ShowMouse
- the same number of times that you called HideMouse to get the
- mouse to appear.
-
-
-
- Hiding the Mouse:
-
- To hide the mouse cursor you call the HideMouse function.
- You can call the HideMouse function multiple times. If the mouse
- is currently visible it will be immediately hidden. If the mouse
- cursor is not visible then a counter is decremented. To make the
- mouse visible again you must call ShowMouse the same number (or
- more) times as you called HideMouse.
-
- Remember that InitMouse will always restore the mouse to the
- first hidden level requiring only a single call to ShowMouse to
- make the mouse cursor visible.
-
- Hiding the mouse does not disable the mouse, it only causes
- the mouse cursor to not be displayed. All mouse functions are
- still fully operational. If the mouse is moved the mouse position
- will be updated even if the cursor is hidden.
-
- Remember, *always* hide the mouse before writing to the
- screen. Failure to do so can cause the screen to be disrupted.
- This is particularly true if you are using an ISR, since the ISR
- assumes that if the mouse is visible it is ok to update the mouse
- cursor position.
-
-
- Reading the Mouse Position:
-
- There are two ways to handle reading the mouse. You can
- either used the old polled method which since it operates fully
- under program control keeps you out of trouble, or you can use
- the included ISR to perform the activity as a background task.
-
-
- Polled Mouse:
-
- In the polled method you can locate the mouse by placing a
- call to the ReadMouse function. The ReadMouse function will
- update the current mouse position variables each time it is
- called. Thsi has the disadvantage that you must place the
- ReadMouse call in the program where it will be called often
- enough to keep the variables updated at a desirable rate.
- Sometimes this entails "sprinkling" the ReadMouse calls in
- various critical parts of the program.
-
-
- ISR Mouse:
-
- An alternate approach is to use an ISR to perform the
- function. There are two types of ISRs that can be used. One that
- is generated by the mouse itself when ever an action occurs, or
- one by the system that periodically checks the mouse status. The
- Mouse unit comes with a system generated ISR that ties in to the
- system clock to periodically update the mouse once every 55ms.
- This has the advantage that mouse drivers that do not support the
- Mouse ISR functions.
-
-
- ISR programming:
-
- Remember when using program based ISRs you are using re-
- entrant coding. You must use extreme care that you do not use
- functions inside the ISR which are not re-entrant. This is
- because the ISR is entered via an interrupt, which means that you
- do not know where it came from. It could very well have
- interrupted the program in the middle of a routine that is not
- re-enterable. The provided ISR function uses the ReadMouse,
- ShowMouse, and HideMouse functions. Thus be very careful if you
- change these procedures so that they do not conflict with the ISR
- itself.
-
- The ReadMouse, ShowMouse, and HideMouse procedures all have
- a re-entrant test at the beginning to prevent the ISR from
- entering the function if it is currently in use. This is required
- because the procedures are not re-entrant.
-
- Since the mouse routines are not re-entrant, all other
- procedures that use the mouse set a flag which is used to inhibit
- the mouse ISR from entering them. Not that the Graphics library
- functions are not re-enterable, this means that you cannot use
- the HideMouseArea function when using the ISR. This is because
- with the HideMouseArea function, it is possible to write to the
- display while the mouse is visible since the mouse is only hidden
- when it is in the update area. This action is not acceptable
- since that means that the mouse would be on the screen while you
- are changing the display, and that means an interrupt can occur
- within a graphics library function, with a mouse cursor update
- generated by the ISR.
-
- There is also the problem that the Turbo graphics library
- does not use the extended EGA function calls the set the EGA
- registers when the mouse is present so that the mouse can keep
- track of the register status (many critical EGA registers are
- non-readable). This will also cause problems. As a general rule,
- it is best to avoid using the HideMouseArea function unless you
- are absolutely sure of your program and it's environment. Use the
- Generic HideMouse function instead. You'll probably save yourself
- a lot of headaches.
-
-
-
- Mouse Positioning:
-
- The value returned in the mouse position variables depends
- on whether the TextMouse flag is true or false. If true, then the
- values will be related to the character position on the screen.
- If the TextMouse flag is false, then it will be related to the
- graphic pixel position. The button information is also returned,
- and if a button was pressed, the action is noted, and the mouse
- position at the time it was pressed is saved.
-
-
- Mouse simulation:
-
- If the mouse is not available, then the mouse positioning
- can be set by the program. calling the ReadMouse function
- periodically in your program will maintain the simulated mouse
- positioning information. If the mouse simulation is enabled, then
- a simulated mouse cursor will be displayed. The simulated mouse
- cursor will be updated on the display each time the mouse cursor
- position information is changed either by the mouse itself, or by
- the program placing new values in the MouseX and MouseY position
- variables.
-
- If the mouse is available, and the mouse simulation is
- enabled, then the simulated cursor will track the mouse. The
- tracking is performed by the ReadMouse function. Each time it is
- called, the mouse cursor is updated if it has moved.
-
-
-
- Text verses Graphic positioning:
-
- When the InitMouse function is called, it looks at the
- BIOS CrtMode flag to determine how to set the mouse positioning
- information. Various flags and registers are set based on the
- information read from the BIOS. For non-standard displays that
- the InitMouse procedure cannot adapt to, the flags and registers
- can be overwritten by the user program after the call to the
- InitMouse procedure.
-
-
-
- Public variables:
-
- A number of variables in the Mouse unit are available to
- to programs that use it. They are provided to allow the program
- to determine the current status of the mouse and/or to be able to
- override the default values selected by the InitMouse procedure.
-
-
- CrtMode : Byte absolute $40:$49; {BIOS Crt mode flag}
- CrtCols : Word absolute $40:$4A; {BIOS Crt col cnt}
- CrtRows : Byte absolute $40:$84; {BIOS Crt row cnt}
- SysClk : Word absolute $40:$6C; {BIOS system clock counter}
- CursorMode : Word absolute $40:$60; {BIOS cursor mode storage}
-
- There are five BIOS variables used by the mouse unit to
- determine the type and mode of the display. These variables are
- used to determine the mouse position translation values to use.
- The InitMouse procedure uses these values to update the
- MouseText, MouseTextWidth, MouseTextHeight, MaxCrtX, MaxCrtY, and
- ZeroMouse variables. They are provided as public variables so
- that the programs which use the Mouse unit can also have access
- to them.
-
-
- MouseInstalled : Boolean; {InitMouse - True if mouse is operable}
-
- If a Mouse was detected by the InitMouse procedure the
- MouseInstalled flag will be set to true. If a Mouse is not found,
- then the flag is set to false. If you wish to temporarily
- disconnect the mouse routines you can set the flag to false at
- anytime after calling InitMouse. This will not disable the mouse,
- only the calls to the mouse in the Mouse unit. If the mouse
- cursor is currently being displayed, and the external mouse
- driver is being used to update the cursor position, it will
- continue to maintain the cursor on the screen. The MouseX and
- MouseY position variables are only updated from the mouse when
- the MouseInstalled flag is true.
-
-
- MouseError : Integer; {InitMouse - Error code}
-
- The MouseError flag is used to determine why the mouse is
- not available. The variable is updated each time the InitMouse
- procedure is called. A value of -1 means that the mouse is
- available. Generally If the MouseError flag is -1, the
- MouseInstalled flag will be true unless your program has turned
- the MouseInstalled flag off for some reason.
-
- If there was no mouse driver found to be installed in the
- computer (as determined by not finding a driver attached to
- interrupt $33) the MouseError variable will be set to 1. If a
- driver is available, but no mouse was found, then the MouseError
- variable is set to 0.
-
-
- MouseType : Integer; {InitMouse - Mouse Type}
-
- The MouseType variable tells you what kind of mouse is
- attached to the computer. If no mouse is found the variable is
- set to 0. If a single button mouse is found it is set to 1. It is
- set to 2 for a two button mouse, and three for a three button
- mouse.
-
- MouseClicked : Boolean; {ReadMouse - True if button was clicked}
-
- The MouseClicked variable indicates when a mouse button has
- been pressed. The flag is provided as a public variable primarily
- to allow mouse simulation programming to set or clear the flag.
- Normally you should use the MouseClick function to determine the
- condition of the MouseClicked flag since it automatically clears
- the flag in preparation for the next click.
-
-
- MouseButtons : Word; {ReadMouse - Current mouse button status}
-
- Each time the ReadMouse function is called, this flag is
- updated with the current mouse button status. You can look at the
- flag at any time to determine the current state of the buttons.
-
-
- MouseClickButton : Word; {ReadMouse - Click button status}
-
- The MouseClickButton variable is updated by the ReadMouse
- function. The variable is updated by the ReadMouse function
- whenever a new mouse button is pressed.
-
-
-
-
- MouseX : Integer; {ReadMouse - Mouse X Position}
- MouseY : Integer; {ReadMouse - Mouse Y Position}
-
- The MouseX and MouseY variables are updated each time the
- ReadMouse procedure is called. The variables reflect the current
- mouse position at the time that the mouse is interrogated via the
- ReadMouse function. In the case where the MouseInstalled flag is
- set to false the variables are not updated, however if the mouse
- simulator is enabled the simulated mouse position on the screen
- will be updated based on the values found in the MouseX and
- MouseY variables each time the ReadMouse function is called.
- Calling the SetMousePosition procedure will load new
- position information in the variables. Thus if your program is
- simulating a mouse, it can use the SetMousePosition procedure to
- update the variables, and use the ReadMouse procedure to update
- the simulated cursor on the screen.
-
-
-
- ClickMouseX : Integer; {Mouse X Click Position}
- ClickMouseY : Integer; {Mouse Y Click Position}
-
- The ClickMouseX and ClickMouseY variables are updated by the
- ReadMouse routine when ever a button it pressed. They reflect the
- current mouse position at the time the button was pressed. They
- are only updated when the button is depressed. The button must be
- released before the variables will be updated again.
-
-
-
- MousePressX : Integer; {last mouse button pressed position}
- MousePressY : Integer;
-
- The MousePress function returns the information provided by
- the associated mouse driver function. The position the mouse was
- in at the last time the specified button was pressed is returned
- in the MousePressX and MousePressY variables. These values are in
- the mouse driver virtual format. You can use the GetMx and GetMy
- functions to convert the values to real screen position
- information.
-
-
-
-
- MouseReleaseX : Integer; {last mouse button release position}
- MouseReleaseY : Integer;
-
- The MouseRelease function returns the information provided
- by the associated mouse driver function. The position the mouse
- was in at the last time the specified button was released is
- returned in the MousePressX and MousePressY variables. These
- values are in the mouse driver virtual format. You can use the
- GetMx and GetMy functions to convert the values to real screen
- position information.
-
-
-
-
- MouseHideX1 : Integer; {HideMouseArea - Mouse hide area}
- MouseHideY1 : Integer;
- MouseHideX2 : Integer;
- MouseHideY2 : Integer;
-
- The MouseHide variables reflect the current mouse
- conditional hiding area. The conditional hide is a special
- function that is not available with all mouse drivers, and it has
- problems with EGA displays unless a special BIOS interface is
- used. The variables are set by the HideMouseArea procedure.
-
-
- Since programs generated by the Borland compilers do not
- make use of the special BIOS routines, it is recommended that you
- do not use the conditional hide if you are using an EGA mode
- display. If the mouse simulator is being used, the conditional
- Mouse hiding will work properly since we have full control over
- the mouse. It is only when the external mouse driver is used that
- the problem exists.
-
- An exception is if you are using a mouse ISR. In this case
- you should not use the simulated mouse cursor because the Borland
- graphics library and screen controls are not re-entrant. As a
- general rule, if you aren't sure, stay away from this function.
- It's not worth the headaches.
-
-
-
-
- MouseAreaX1 : Integer; {SetMouseArea - Mouse bounded area}
- MouseAreaY1 : Integer;
- MouseAreaX2 : Integer;
- MouseAreaY2 : Integer;
-
- The MouseArea variables contain the limits that the mouse is
- allowed to travel within on the screen. The mouse cursor will not
- travel outside this area. The variables are set by the
- SetMouseArea procedure.
-
-
-
- MouseGStyle : Integer = 1; {selected graphic mouse style}
-
- The MouseGStyle variable indicates which graphic mouse
- cursor is currently being used. When InitMouse is called the
- mouse cursor is always returned to style type one. The variable
- is also updated by the MouseGraphicCursor procedure. If a custom
- mouse cursor is loaded by the SetMouseGraphicCursor procedure the
- MouseStyle variable will be set to -1.
-
-
- MouseTStyle : Integer = 0; {selected text mouse style}
-
- The MouseTStyle variable indicates which text mouse cursor
- is currently being used. When InitMouse is called the mouse
- cursor is always returned to style type zero. The variable is
- also updated by the MouseTextCursor procedure. If a custom mouse
- cursor is loaded by the SetMouseTextCursor procedure the
- MouseStyle variable will be set to -1. If a style type of zero is
- used, then the current existing hardware cursor is used as the
- mouse cursor.
-
-
- MouseState : Integer = -1; {Negative = mouse hidden}
-
- The MouseState variable is used by Mouse unit to keep track
- of the mouse cursor condition. It normally will take on a
- negative value if the mouse is hidden, or a value of 0 if the
- mouse is visible. The MouseState variable is decremented by one
- each time the HideMouse function is called, and incremented by
- one each time the ShowMouse function is called. It never achieves
- a value higher than zero. You should never change this variable
- with your program it is provided for informational purposes only.
-
-
- MouseVisible : Boolean = false; {true = mouse is visible}
-
- When the Mouse is visible on the screen this flag is set to
- true. When the mouse is hidden it is set to false. The flag
- should not be changed by your program. It is provided only so
- that you can determine the current state of the mouse cursor. The
- HideMouse and ShowMouse procedures are used to make the mouse
- visible or to hide it.
-
-
- MouseCondo : Boolean = false; {true = conditional mouse hiding}
-
- When the Mouse is operating in the conditional hide state as
- specified by calling procedure MouseAreaHide, the MouseCondo flag
- is set true. Normal mouse operation will cause the flag to be set
- to false. The flag should not be changed by your program it is
- provided only as a means to determine the current state of the
- mouse area hide condition.
-
-
-
-
- MouseReDraw : Boolean = false; {true = mouse needs to be redrawn}
-
- The MouseReDraw flag is used by the mouse cursor simulator.
- When it is true, it forces the mouse cursor to be redrawn. This
- flag can be set by your program to force the cursor to be
- redrawn. It is set internally anytime the mouse cursor bumps
- against the edge of the screen while the simulated BGI cursor is
- being used.
-
- The reason behind this is because the BGI driver cannot
- handle images being drawn outside the screen. Thus in order to
- allow the mouse cursor to move off the edge of the screen, it
- must be redrawn each time to adjust the cursor image to the area
- of the screen that it can be displayed on. This flag should never
- be set to false by your program. You can however set it to true
- if you have a need to do so.
-
-
-
- TextMouse : Boolean = false; {true = text mode type mouse}
-
- The TextMouse flag is set by a call to the InitMouse
- procedure. If one of the standard text modes is determined (as
- found by seeing a value less than 4 or a value of 7 in the
- CrtMode byte), the TextMouse flag is set to true. Otherwise it is
- set to false. If you are using a custom display text mode then
- you may need to set this flag to true after the call to
- InitMouse.
-
-
-
- ZeroMouse : Boolean = false; {true = text mouse starts at 0}
-
- The ZeroMouse flag controls whether the mouse positioning is
- zero based or one based. That is, whether the screen position
- starts at location 0,0 or 1,1. The 0,0 starting position is used
- during graphics mode, while the 1,1 starting position is used
- during text mode. If you are using a text mode that performs
- positioning starting at 0,0 you can set the ZeroMouse flag to
- false after calling InitMouse.
-
-
-
- HercGraphMouse : Boolean = false; {true = Herc graph mode mouse}
-
- When A Hercules display is used in graphics mode, this flag
- is set to true. The function SetHercGraph controls this flag. You
- should not set this flag directly. it should only be set by a
- call to SetHercGraph. You can however use it to determine if the
- mouse is operating in the Hercules Graphics mode.
-
-
-
-
- MouseTextWidth : Word = 8; {size of text on screen for mouse}
- MouseTextHeight : Word = 8;
-
- The MouseTextWidth and MouseTextHeight variables contain the
- size of the text characters on the screen. These values are used
- to convert from the mouse virtual position information to the
- real screen information, or from real screen position information
- to the virtual mouse position information.
- The MouseText size values are set when a call is placed to
- the InitMouse procedure. If the default values determined by the
- InitMouse procedure do not match those that you are using you can
- change the values at anytime after calling the InitMouse
- procedure to set them to the desired values.
-
-
-
-
- MaxCrtX : Word = 80; {Maximum size of text screen}
- MaxCrtY : Word = 25;
-
- The MaxCrtX and MaxCrtY variables are set by the InitMouse
- function. The values are based on those found in the BIOS
- variables CrtCols, and CrtRows. These secondary variables are
- used because the BIOS variables do not always contain
- proper values. The InitMouse procedure adjusts for the correct
- values based on the machine and display being used.
-
-
-
-
- MouseColor : Word = white; {mouse cursor color}
-
- When you use the BGI simulated mouse cursor you have control
- over the mouse cursor color. The MouseColor variable determines
- the color of the simulated mouse cursor. You can change this
- variable at any time. It is defaulted to white when the program
- starts. Since this is a typed variable, you can change it to
- start with any value you wish, or you can change it at run time
- to a desired color.
- The MouseColor variable has no effect on the cursor
- generated by the standard mouse driver. The mouse driver always
- generates a white cursor.
-
-
-
- UseMouseSim : Boolean = false;{true = use simulated mouse cursor}
-
- The UseMouseSim flag is a user flag that you can set to true
- or false. When true the simulated mouse cursor will be used. When
- false the Mouse driver's own cursor will be used. The mouse
- cursor should always be off before changing this flag. You can
- change the condition of the flag at any time that the mouse
- cursor is not visible.
-
-
- MouseImageX : Integer = 0; {current mouse XY image position}
- MouseImageY : Integer = 0;
-
- The MouseImageX and MouseImageY position variables are provided
- to allow you to know where the simulated BGI mouse image actually
- is on the screen. The mouse position is determined by a
- combination of the "Hot Spot" location and the upper left corner
- of the mouse image. Adding the two values will reveal the
- location of the mouse cursor Hot Spot on the screen. These
- variables are provided for informational use only. They should
- not be changed by the user program since doing so will disrupt
- the mouse simulator.
-
-
- MaskType = record {mouse graphic cursor def}
- Def: array [0..1, 0..15] of word; {graph cursor def}
- HotX, HotY: integer; {hot spot X,Y}
- end;
-
- The MaskType defines how a custom graphic cursor can be
- created. The mouse cursor mask consists of two arrays of 16 words
- each. The first array is the mask value that is used to turn off
- selected bits under the mouse cursor, and the second array of 16
- words contains the mask value that is used to generate the cursor
- in the foreground. The first word in the array is the top line of
- the cursor, the last word in the array is the bottom line of the
- cursor.
-
- The "hot spot", which is the location related to the top
- left corner of the mouse cursor image, specifies the location
- where all mouse activity is tied to. The HotX and HotY values are
- relative to the top left corner of the mouse image.
-
- You can use the SetMouseGraphic cursor to define a custom
- mouse cursor of your own.
-
-
- MouseTextType = record
- Select : Word; {soft or hard mouse}
- Start : Word; {mouse start definition}
- Stop : Word; {mouse end definition}
- end;
-
-
- The MouseTextType defines what a text mouse cursor looks
- like. The Select value determines whether it will be a hardware
- cursor, or a software cursor. Start is the starting cursor line
- for a hardware cursor, or the and mask for a software cursor.
- Stop is the ending cursor line for a hardware cursor, or the OR
- mask for a software cursor.
-
-
- Refer to the mouse programmer's manual for more information
- on programming a mouse cursor.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Local variables:
-
- In addition to the public variables, there are some local
- variables used by the Mouse unit. The definitions are provided
- here for reference purposes only.
-
-
-
-
- MouseBusy : Boolean; {Mouse routines are in use}
-
- The MouseBusy flag is set when ever a mouse routine is
- entered. This is used to notify an ISR that the mouse is
- currently in use and should not be disturbed.
-
-
-
-
- OldMouseX : Integer; {Previous mouse X Position}
- OldMouseY : Integer; {Previous mouse Y Position}
-
- The OldMouse variables are used by the ReadMouse procedure
- to determine when the mouse has moved. When the values stored in
- OldMouseX and OldMouseY no longer match the new values found in
- MouseX and MouseY then simulate mouse cursor is updated if it is
- enabled. The variables are available for the program to look at,
- but don't change the values since it will disrupt the simulated
- cursor display.
-
-
-
- CustomMask : MaskType; {storage for custom graphic cursor data}
-
- When a custom graphic mouse cursor is loaded it is saved,
- in this variable is updated so that the simulated BGI mouse
- cursor can have access to the data. This record should never be
- loaded directly. You should use the SetMouseGraphicCursor
- procedure to update the data in this record.
-
-
-
-
- MouseReg : Registers; {registers used to call mouse interrupt}
-
- The MouseReg variables are used by the mouse driver
- interface routines when placing calls to and from the mouse
- interrupt driver. The Registers type used by this record is the
- only reason that the Dos unit is used by the Mouse Unit. They are
- declared as a private global variable so that time is not wasted
- creating the variables on the stack each time a mouse routine is
- called.
-
-
-
- MouseTemp : Integer = 0; {Temp mouse storage variable}
-
- MouseTemp is just a fast access temporary local variable
- used by the simulated mouse cursor routines. Beyond that, it has
- not specific purpose.
-
-
-
- MouseStack : MousePtrP; {MouseStack points to last rec on stack}
- {if nil then there is nothing on stack}
-
- The MouseStack is used by the PushMouse and PopMouse
- functions. Note: Not all mouse drivers support the ability to
- save and restore the mouse status. You should check your mouse
- driver before using these functions. Never ever attempt to
- directly access the data on the mouse stack since it may cause
- the program to crash, or at least disrupt the mouse itself.
-
-
-
- Local BGI graphic variables
-
- The following variables are used locally by the simulated
- BGI mouse cursor functions.
-
-
- MouseBack : pointer = nil; {^old image under BGI mouse cursor}
- MouseMask : pointer = nil; {^BGI mouse cursor mask}
- MouseFore : pointer = nil; {^BGI mouse cursor overlay}
- MouseSize : word = 0; {storage size for mouse image 0=empty}
-
- The MouseBack, MouseMask, and MouseFore pointers contain the
- pointers to where the mouse images are saved on the heap.
- MouseBack contains the screen image that is behind the mouse.
- MouseMask contains the AND mask used to blank out selected screen
- areas under the mouse cursor, and MouseFore contains the mouse
- cursor foreground image. MouseSize specifies how big the mouse
- image is. All four variables are updated each time the InitMouse
- function is called.
-
-
- EndImageX : Integer = 0; {End of Mouse X image}
- EndImageY : Integer = 0; {End of Mouse Y image}
-
- The EndImage variables are used by the simulated BGI mouse
- cursor to determine where the end of the mouse cursor image is on
- the screen.
-
-
- OldImageX : integer = 0; {position of image under mouse }
- OldImageY : integer = 0;
-
- The OldImage variables are used to keep track of the last
- known position of the mouse cursor. This is used when the old
- mouse cursor is undrawn before it is moved to its new location.
-
-
- Available Mouse Functions:
-
- The following mouse functions are available to the program
- using the Mouse Unit. For More information on the mouse
- functions, refer to the MicroSoft Mouse Programmer's technical
- Reference Guide.
-
-
- { Function 0 - Initialize mouse software and hardware }
- procedure InitMouse;
-
- The InitMouse procedure is used to initialize the mouse when
- ever the program is first started or the display mode is changed.
- This keeps the internal mouse information synchronized to the
- display in use.
-
-
-
-
- { Function 1 - show mouse cursor }
- procedure ShowMouse;
-
- The ShowMouse function is called to display the mouse. If a
- previous HideMouse was called, the same number of ShowMouse calls
- must be performed to show the mouse.
-
-
-
-
- { Function 2 - hide mouse cursor }
- procedure HideMouse;
-
- The HideMouse function hides the mouse cursor. This does not
- disable the mouse, it only hides the cursor. All mouse functions
- continue to operate normally. Use this function before writing
- to the screen so that the mouse cursor won't be disrupted.
-
-
-
- { Function 3 - read mouse position and button status }
- { Use GetMx, GetMy to read the mouse position info in MouseX, MouseY, }
- { or ClickMouseX, ClickMouseY }
- procedure ReadMouse;
-
- The ReadMouse function should be called periodically to
- update the program's mouse variables. Each time this function is
- called, the mouse is interrogated and the variables updated on
- the results. If the mouse has moved, and the simulated mouse
- cursor is being used, then the mouse cursor will be moved to
- reflect the new position.
-
- The ReadMouse function should be called periodically by your
- program to insure that the mouse variables are properly updated.
- A good place to call the function is in the same routine that you
- use to check for keyboard input. Alternately you could attach it
- to an ISR service routine to update the variables automatically.
-
-
-
-
- { function 4 - sets mouse position }
- { Recommended calling method: }
- { SetMousePosition(PutMx(X),PutMy(Y)); }
- procedure SetMousePosition(X,Y:Integer);
-
- The SetMousePostion function places the mouse cursor at the
- specified position on the display. This function expects the
- virtual mouse coordinates to be used. Normally this means that
- you should use the PutMx and PutMy functions to adapt your own
- screen position information to the values wanted by the mouse
- driver.
-
-
-
-
- { function 5 - gets button press information }
- { Recommended calling method: }
- { Status := MousePress(Button,Count); }
- { Click position is available in vars ClickMouseX and ClickMouseY}
- function MousePress(Button:Word; var Count:Word):Word;
-
- The MousePress function returns the information provided by
- the associated mouse driver function. The Button value specifies
- which button information to get, and the Count value returns the
- number of times the button was pressed since the last call. The
- position the mouse was in at the last time the specified button
- was pressed is returned in the MousePressX and MousePressY
- variables. These values are in the mouse driver virtual format.
- You can use the GetMx and GetMy functions to convert the values
- to real screen position information.
-
-
-
-
- { function 6 - gets button release information }
- { Recommended calling method: }
- { Status := MouseRelease(Button,Count); }
- { Click position is available in vars ClickMouseX and ClickMouseY}
- function MouseRelease(Button: Word; var Count:Word):Word;
-
- The MouseRelease function returns the information provided
- by the associated mouse driver function. The Button value
- specifies which button information to get, and the Count value
- returns the number of times the button was released since the
- last call. The position the mouse was in at the last time the
- specified button was released is returned in the MouseReleaseX
- and MouseReleaseY variables. These values are in the mouse driver
- virtual format. You can use the GetMx and GetMy functions to
- convert the values to real screen position information.
-
-
-
-
- { functions 7 and 8 - sets area where the mouse is allowed to run }
- { Recommended calling method: }
- { SetMouseArea(PutMx(x1),PutMy(y1),PutMx(x2),PutMy(y2)); }
- procedure SetMouseArea(x1,y1,x2,y2:Integer);
-
- The SetMouseArea function allows you to limit mouse movement
- to a specific area of the screen. This function expects the
- virtual mouse coordinates to be used. Normally this means that
- you should use the PutMx and PutMy functions to adapt your own
- screen position information to the values wanted by the mouse
- driver.
-
-
-
- { function 9 - sets the graphics cursor style }
- procedure MouseGraphicCursor(Style:Integer);
-
- The MouseGraphicCursor function allows you to load one of
- the predefined Mouse cursors. The specific mouse cursor style is
- passed as the value contained in the "Style". Refer to the
- constant table in the MOUSECUR.PAS include file for the various
- mouse styles that are supplied by the Mouse unit.
-
-
-
- { function 9 - sets a custom graphics cursor style }
- procedure SetMouseGraphicCursor(var Mask:MaskType);
-
- This function allows you to load a custom graphics mouse
- cursor. The cursor information is passed in the Mask record.
- Refer to the Mouse technical manual on how to create a custom
- mouse cursor.
-
-
-
-
- { function 10 - sets the text cursor style }
- procedure MouseTextCursor(Style:Word);
-
- This function allows you to load one of the predefined text
- mouse cursors. The specific mouse cursor type is passed as the
- value contained in the "Style". Refer to the constant table in
- the MOUSECUR.PAS include file for the various mouse style that
- are supplied by the Mouse unit.
-
- A value of 0 will cause the existing hardware cursor to be
- used as the text mouse cursor. Note: a Style value of 1 will
- cause a block styled hardware cursor to be used. This will change
- the existing hardware cursor to become a block. Values greater
- than one will cause one of the predefined software cursors to be
- loaded.
-
-
-
-
- { function 10 - sets the text cursor style }
- procedure SetMouseTextCursor(Select,Start,Stop:Word);
-
- This function allows you to load a custom text mouse cursor.
- The cursor information is passed in the Select, Start, and Stop
- values. Refer to the Mouse technical manual on how to create a
- custom mouse cursor. The MouseTStyle is set to a -1 when a custom
- mouse cursor is loaded.
-
-
-
- { function 11 - Read Mouse Motion counters }
- procedure ReadMickey(var X,Y:Integer);
-
- This function returns the "Mickey" count since the last time
- the function was called. A Mickey is the actual count positional
- information that comes from the mouse. This is different than the
- mouse virtual position information which is derived from the
- Mickey count. Refer to the mouse technical manual for further
- information on Mickeys and their relationship to positional
- information.
-
-
-
- { function 12 - Set Mouse Interrupt service routine and mask }
- procedure SetMouseISR(Mask:Word; Address:Pointer);
-
- You can attach an interrupt service routine to the mouse by
- using the SetMouseISR function. Extreme care should be exercised
- when using this function as with all interrupt service routines.
- It should be noted that not all mouse drivers support the mouse
- ISR routines, and that there are some differences in the way the
- mouse ISR is handled in those drivers that do support the
- function. Refer to the mouse technical manual for further
- information on mouse ISR handlers.
-
-
-
- { function 13 and 14 - Light pen emulation on/off }
- procedure LightPen(Flag:Boolean);
-
- You can enable or disable a light pen emulation mode by
- calling this function with Flag set to true to enable the light
- pen emulation, or false to turn it off.
-
-
-
- { function 15 - sets the mickey to pixel ratio }
- procedure SetPixeltoMickey(X,Y:Integer);
-
- The SetPixeltoMickey function sets the conversion value used
- to translate the Mickey values received from the mouse into
- the virtual pixel locations used by the mouse driver. Refer to
- the mouse technical manual for further information on Mickeys and
- their relationship to positional information.
-
-
-
- { function 16 - Conditional Mouse Hide - hides mouse if in area }
- { use ShowMouse after using this function - }
- { just like regular HideMouse. }
- {Recommended calling method: }
- {If HideMouseArea(PutMx(x1),PutMy(y1),
- PutMx(x2),PutMy(y2)) then DoSomething;}
- procedure HideMouseArea(x1,y1,x2,y2:Integer);
-
- The HideMouseArea function allows you to conditionally hide
- the mouse cursor if it is in a specific screen area. This can
- help to reduce the screen flicker that can occur when the mouse
- is hidden during writing by specifying that the mouse only needs
- to be hidden if it is within the screen area being written to.
-
- Note: The MouseHideArea function will not work properly on EGA
- displays when using the internal mouse driver cursor. This is
- because the mouse driver must keep track of the status of a
- number of the EGA registers. These registers are not readable.
- This requires that the user program perform all CRT controller
- register changes via special extended BIOS calls. Unfortunately,
- most programs do not do this. The Turbo Pascal is one of those
- programs that do not do this. If you are using an EGA display
- mode it is recommended that you use the generic MouseHide
- function instead.
-
- This function expects the virtual mouse coordinates to be
- used. Normally this means that you should use the PutMx and PutMy
- functions to adapt your own screen position information to the
- values wanted by the mouse driver.
-
- This function should be avoided when using an ISR to control
- the mouse since re-entrancy conflicts will most likely result if
- you do so. If in doubt avoid this function.
-
-
-
-
- { function 19 - Set Double Speed Threshold }
- procedure MouseThreshold(Threshold:Integer);
-
- The mouse driver can be set to provide a double speed
- movement when the mouse is moved very quickly. The point at which
- the speed is doubled is the mouse double speed threshold which is
- measured in Mickeys per second. This value can be changed by
- calling the MouseThreshold function with the new desired values.
- Refer to the mouse technical manual for further information on
- Mickeys and their relationship to positional information.
-
-
-
-
-
- { function 20 - Swap current Mouse ISR with a new one}
- { Returns old ISR and mask in the calling variables }
- procedure SwapMouseISR(var Mask:Word; var Address:Pointer);
-
- You can swap the current interrupt service routine (ISR) for
- the mouse with a new handler by using the SwapMouseISR function.
- Extreme care should be exercised when using this function as with
- all interrupt service routines.
-
- It should be noted that not all mouse drivers support the
- mouse ISR routines, and that there are some differences in the
- way the mouse ISR is handled in those drivers that do support the
- function. Refer to the mouse technical manual for further
- information on mouse ISR handlers.
-
-
-
- { function 29 - Set Mouse Page }
- procedure SetMousePage(Page:Word);
-
- Normally the mouse defaults to video page 0. You can change
- the page that the mouse is on by calling this function with the
- appropriate page number in 'Page'.
-
-
-
- { function 30 - Get Mouse Page }
- function GetMousePage:Word;
-
- The GetMousePage function allows you to find out which video
- page the mouse is currently on. The function returns the page
- number as a function result.
-
-
-
-
- {Set Hercules Graphics page for Mouse (not a standard function)}
- { 0= graph pg 0, 1= graph pg 1, -1 = text mode }
- procedure SetHercMouse(Pg:Integer);
-
- This procedure is not a standard mouse function. It is
- however needed to work with the Hercules graphics display. When
- you use the Hercules graphics display you must call this with the
- proper display page after you call InitGraph, but before you call
- InitMouse. InitGraph needs CrtMode to be at 7 to detect the Herc
- display, but the Mouse needs it at 5 or 6 to detect when the Herc
- card is in graphs mode. (The Herc card has no provision for
- telling the system that it is graphics mode.) Note: Be sure to
- call this procedure with a Pg of -1 if you turn graphics off or
- anytime before you call InitGraph or DetectGraph. The Mouse unit
- contains an Exit procedure that calls SetHercMouse with a value
- of -1 if a Hercules graph mode was selected so that the CrtMode
- byte will be properly restored on exit from the program.
-
-
- ----------------------------------------------------------------
- The following procedures use the mouse functions to provide
- a higher level of control over the mouse:
-
- { Normalizes a mouse X position to standard position info }
- function GetMx(X:Integer):Integer;
-
- The GetMx function is used to convert a virtual mouse X
- position to a real screen X position. The data passed in X is
- converted and the result passed back as a function result.
-
-
- { Normalizes a mouse Y position to standard position info }
- function GetMy(Y:Integer):Integer;
-
- The GetMy function is used to convert a virtual mouse Y
- position to a real screen Y position. The data passed in Y is
- converted and the result passed back as a function result.
-
-
- { converts a standard X position to a mouse X position }
- function PutMx(X:Integer):Integer;
-
- The PutMx function is used to convert real screen X position
- information to a virtual mouse X position. The data passed in X
- is converted and the result passed back as a function result.
-
-
- { converts a standard Y position to a mouse Y position }
- function PutMy(Y:Integer):Integer;
-
- The PutMy function is used to convert real screen Y position
- information to a virtual mouse Y position. The data passed in Y
- is converted and the result passed back as a function result.
-
-
- { Check if mouse is currently in the specified area}
- { returns true if it is, false if not}
- { Recommended calling method: }
- { If MousePointIn(GetMx(Mx),GetMy(My),
- x1,y1,x2,y2) then DoSomething;}
- function MousePointIn(Mx,My, x1,y1,x2,y2:Integer):Boolean;
-
- This function returns a true result if the point value
- passed in My and My is within the rectangle described by
- x1,y1,x2,y2. The point is not with the rectangle it returns a
- false condition. The function can actually be used for any
- generic point in rectangle application. When using it to test
- the mouse position, you should use the GetMx and GetMy functions
- to convert the mouse virtual position information to real screen
- position information (assuming that you are using real screen
- position information in x1,y1,x2,y2).
-
-
- {has the mouse been clicked recently?}
- function MouseClick:Boolean;
-
- The MouseClick function returns the current status of the
- MouseClicked variable and automatically clears it in the process
- in preparation for the next test. This function is provided to
- make testing of the flag easier. You can handle the flag
- yourself, but it is recommended to process through this function
- for future compatibility.
-
-
- {Hooks the Mouse function to the system clock}
- {State = true hooks the mouse up }
- {State = false disconnects the mouse}
- procedure MouseClock(State:Boolean);
-
- The MouseClock function hooks the mouse ReadMouse procedure
- to the system clock. This causes the mouse status to be
- periodically updated once every 55ms.
-
-
- {Pushes current mouse status on the mouse stack}
- {Returns false if not enough heap space to push}
- function PushMouse:Boolean;
-
- The PushMouse function allows you to save the current
- operational condition of the mouse on a stack. The Mouse stack
- uses heap space to store the information. You can then recall the
- saved mouse condition by using PopMouse at a later point in the
- program. Note: Some mouse drivers do not implement the ability to
- save the mouse state. Check with your current mouse driver as to
- whether it can support this function before you use it.
-
- If for some reason the PushMouse function doesn't work, such
- as no heap space to save the mouse condition, the function will
- return a false value. A true value is returned if everything goes
- as planed.
-
-
- {Pops mouse status from the mouse stack.}
- function PopMouse:Boolean;
-
- The PopMouse function is the opposite of the PushMouse
- function. You can restore a previously saved mouse condition by
- using the PopMouse function. If there is nothing to pop, or
- something went wrong the function will return a false condition.
- If everything is went well the function will return a true
- condition.
-
-
- {Get rid of mouse stack}
- procedure ZapMouseStack;
-
- The ZapMouseStack procedure clears the mouse stack of any
- extra saved mouse conditions. If you are uncertain of the Mouse
- Stack condition you can call this function to remove all saved
- conditions. When done the mouse will have the conditions that
- were present with the first mouse save on the mouse stack.
-
-
- Acknowledgments:
-
- While there is very little left of the Mouse program that
- relates to the earlier versions, I do wish to thank the following
- people for their earlier work.
-
- The original idea for MOUSE was based on the MOUSE4 program
- by Richard Sadowsky. The Cursor styles were based on the ideas
- presented in EGAMouse by Eduardo Martins. Special thanks to Kim
- Kokkonen for reminding me about the differences between Dos 2.x
- and Dos 3.x interrupt use detection.
-
- I also wish to thank the countless users and other
- interested parties who have provided inputs for enhancements and
- their continued support and encouragement.
-
- Any stupid mistakes are my own.
-
- General disclaimer:
-
- There have been many people who have provided input and
- encouragement on the Borland Pascal forum of Compuserve which has
- allowed this program to grow and mature. It should be realized
- though that like all software, there can never be assured a 100%
- reliability, or that the program will fit your needs exactly.
-
- I cannot warrant that this program will work flawlessly for
- you. Only you can be the judge of that. As such, if it don't
- work, blows up in your face, or the sky falls on your head, don't
- blame me, I warned ya!
-
-
-
-
- ----------------end-of-author's-documentation---------------
-
- Software Library Information:
-
- This disk copy provided as a service of
-
- The Public (Software) Library
-
- We are not the authors of this program, nor are we associated
- with the author in any way other than as a distributor of the
- program in accordance with the author's terms of distribution.
-
- Please direct shareware payments and specific questions about
- this program to the author of the program, whose name appears
- elsewhere in this documentation. If you have trouble getting
- in touch with the author, we will do whatever we can to help
- you with your questions. All programs have been tested and do
- run. To report problems, please use the form that is in the
- file PROBLEM.DOC on many of our disks or in other written for-
- mat with screen printouts, if possible. The P(s)L cannot de-
- bug programs over the telephone.
-
- Disks in the P(s)L are updated monthly, so if you did not get
- this disk directly from the P(s)L, you should be aware that
- the files in this set may no longer be the current versions.
-
- For a copy of the latest monthly software library newsletter
- and a list of the 1,800+ disks in the library, call or write
-
- The Public (Software) Library
- P.O.Box 35705 - F
- Houston, TX 77235-5705
- (713) 665-7017
-